Skip to content

link swift libraries when building test executables #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2017

Conversation

dgrove-oss
Copy link
Contributor

Add hook to enable passing in the location of the swift
runtime libraries so we can include them when building
test executables. If we don't do this and we built
dispatch as a shared library and enabled swift support
the link step fails.

Add hook to enable passing in the location of the swift
runtime libraries so we can include them when building
test executables.  If we don't do this and we built
dispatch as a shared library and enabled swift support
the link step fails.
@dgrove-oss
Copy link
Contributor Author

@das @compnerd This matches what the autotools build currently does. If there is a better way to accomplish this in CMake, I'm happy to change the patch. But as far as I can tell, we do need to get these link options when (a) building shared libraries and (b) building dispatch including the swift overlay.

@compnerd, in my version of the patch for swift/utils/build-script-impl, I also define CMAKE_SWIFT_RUNTIME_LIBDIR . I think you may want to pick up some fragments of https://github.com/dgrove-oss/swift/commit/9b5a1491f56ddd711b397afaf7161113408f103c to include in swiftlang/swift#10670

@das
Copy link
Contributor

das commented Jul 1, 2017

hmm, it would be good to have/preserve the ability link against the libdispatch shared library without linking in the swift runtime (which the C unit test binaries shouldn't otherwise need right?)

but it sounds like that is more of a pre-exisisting issue that the autoconf buildsystem already had on Linux ? i.e. we can deal with this separately later on

FWIW we will definitely not be able to have this dependency on Darwin if we want to be able to build a replacement of the libdispatch.dylib that ships with the OS (like we used to be able to with the autoconf buildsystem and is something I would strongly like make work again with CMake)

@das das merged commit 6bbecba into swiftlang:master Jul 1, 2017
@dgrove-oss
Copy link
Contributor Author

dgrove-oss commented Jul 1, 2017

It should work ok on Darwin. The linking/inclusion of the Swift overlay and Swift libraries are conditional on two variables (CMAKE_SWIFT_RUNTIME_LIBDIR and CMAKE_SWIFT_COMPILER) being defined when CMake is invoked (done by swift/utils/build-script). if they aren't defined, then it just builds a straight C library with no Swift dependencies.

@dgrove-oss dgrove-oss deleted the cmark-swift-linking-options branch July 1, 2017 14:16
target_link_libraries(bsdtestharness
PRIVATE
-L${CMAKE_SWIFT_RUNTIME_LIBDIR} -lswiftCore -lswiftSwiftOnoneSupport
-Wl,-rpath -Wl,${CMAKE_SWIFT_RUNTIME_LIBDIR})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding rpaths is discouraged. It can be used as a security issue to interposition other libraries. I think think that we should be trying to do this differently. Furthermore, the -l should not be added when doing the target_link_libraries as it will normally put the right prefix. Finally, -L should be handled via link_directories. Ill put up a PR to address some of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants